<?php
//by willson 105328468@qq.com 2014/10/11
//index page interface

class address_model extends base_model {

	public function __construct() {
		parent::__construct();
	}

	//获取默认地址，已经登录的情况下才返回
	public function default_address() {
		if ($this->member_id>0) {
			$sql = "SELECT * FROM jf_address WHERE member_id='{$this->member_id}' ORDER BY is_default DESC, id DESC LIMIT 1";
			$address = $this->db->get_row($sql);
			//echo $sql;
			if (!$address) $address = $this->_init_address();
		} else {
			$address = $this->_init_address();
		}
		return $address;
	}

	//初始化一个地址对象。
	private function _init_address() {
		$address = new stdClass;
		$address->member_id = 0;
		$address->contactman = '';
		$address->province = '';
		$address->city = '';
		$address->district = '';
		$address->address = '';
		$address->mobile = '';
		$address->zipcode = '';
		$address->is_default = 0;
		$address->idcard = '';
		return $address;
	}
}
